/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package SaleManager.Book.Logic;

import Data.DAO.IBookStore;
import Data.DAO.IDataStore;
import data.pojo.Book;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

/**
 *
 * @author kite
 */
public class SearchBookManage {

    private IDataStore bookDS = new IBookStore();

 
   public Vector<List> searchTableVector(String key, String keywords) {
        return new Vector<List>(toBookTable(bookDS.getObjectsByAttr(key, ".*" + keywords + ".*")));
    }

    public Vector<Vector<String>> toBookTable(List list) {
        try {
            Vector<Book> seList = new Vector(list);
            Vector<Vector<String>> reList = new Vector<Vector<String>>();
            for (int i = 0; i < seList.size(); i++) {
                reList.add((Vector<String>) toBookStringArray(seList.get(i)));
            }
            return reList;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public List toBookStringArray(Book book) {
        Vector<String> list = new Vector<String>();
        list.add(book.getISBN());//ISBN
        list.add(book.getTitle());//title
        list.add(book.getAuthor());//Author
        list.add(((Double) book.getPrice()).toString());//price     
        list.add(String.valueOf(book.getPublisher()));//publicsher
        list.add("");//publicationDate
        return list;
    }
    
}
